import {queryOrderList} from "@src/api/points";
import router from "@src/router";
Component({
  behaviors: [router.routerBehavior],
  data: {
    pageNum: 1,
    pageSize: 10,
    loading: false,
    hasNextPage: true,
    listData: []
  },
  pageLifetimes: {},
  methods: {
    onLogin() {
      this.initLoadingData();
    },
    onPullDownRefresh(){
      this.initLoadingData()
    },
    onReachBottom(){
      if(this.data.hasNextPage){
        this.setData({pageNum: this.data.pageNum+1})
        this.fetchData()
      }
    },
    initLoadingData() {
      this.setData({
        pageNum: 1,
        pageSize: 10,
        hasNextPage: false,
        listData: []
      })
      this.fetchData()
    },
    fetchData() {
      /*暂停刷新*/
      let data = {
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize,
        source: 0
      };
      this.setData({loading: true})
      queryOrderList(data).then(res => {
        if (res.code === 0) {
          let list = res.data.list||[];
          let listData = this.data.listData.concat(list);
          this.setData({listData: listData, hasNextPage: res.data.hasNextPage, loading: false})
        } else {
          this.setData({loading: false})
        }
      }).catch(() => {
        this.setData({loading: false})
      }).finally(()=>{
        wx.stopPullDownRefresh()
      })
    },
    /*按钮点击*/
    itemClick(orderNo) {
      // this.$navigateUtils.navigateTo('memberCardModule','redemptionRecordDetails',[{page:'redemptionRecord'},{orderNo:orderNo}])
    }
  }
})
